<?php

/**
 * O2O团购PC版本
 * ============================================================================
 * * 版权所有 2009-2016 郑州司科计算机科技有限公司，并保留所有权利。
 * 购买网址: http://www.jzphp.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
  * 咨询电话：400-823-0371 QQ：313999875
 * ============================================================================
 * $Author: zzsike $
 * $Time 2016-02-03 sammy $
*/


require_once(dirname(dirname(__FILE__)) . '/appwap.php');
need_login(true);
$daytime=time();
$action=strval($_GET['a']);
if($action=='record'){
	$conditon=array(
			'user_id'=>$login_user['id'],
	);
	$record=DB::LimitQuery('withdraw',array(
		'condition'=>$conditon,
		'order'=>'order by time desc,id desc',
	));
	die(include template('wap_mywithdraw_record'));
}
if ( $_POST ) {
	$withdraw =$_POST;
	if(trim($_POST['money'])=="" ||trim($_POST['bankname'])=="" ||trim($_POST['bankuser'])==""|| trim($_POST['bankno'])==""){
		Session::Set('error', '所有信息均为必填项，请您补充完整要填的信息！');
		redirect( WEB_ROOT . '/wap/mywithdraw.php ');
	}
	if($_POST['money']>$login_user['money']){
		Session::Set('error', '提现金额不能超过您的账户余额！');
		redirect( WEB_ROOT . '/wap/mywithdraw.php ');
	}
	$insert = array(
		'user_id', 'money', 'bank_name','bank_user', 'bank_no', 'state','time'
		);
	$withdraw['user_id']=$login_user['id'];
	$withdraw['money']=trim($_POST['money']);
	$withdraw['bank_name'] =trim($_POST['bankname']); 
	$withdraw['bank_user']=trim($_POST['bankuser']);
	$withdraw['bank_no']= trim($_POST['bankno']);
	$withdraw['state']=1;
	$withdraw['time']=$daytime;
	$table = new Table('withdraw', $withdraw);
	if ($table->insert($insert)) {
		Session::Set('notice', '提现申请提交成功，请耐心等待管理员审核。');
		redirect( WEB_ROOT . '/wap/my.php ');
	} else {
		Session::Set('error', '提现申请提交失败');
	}
}	
die(include template('wap_mywithdraw'));
?>